#!/usr/bin/env python
# coding: utf-8
'''
Created on 2014年7月17日

@author: Administrator
'''

'''
@
'''

from msgpack import packb, unpackb

input = {'vcheck': 1, 'user_id': 100059076, '_os': 'i', 'd_ver': '0.0.186', 'token': '1988866', 'app_ver': '2.4.3', 'user_stage_open':True}

FILE_PATH = r"/Users/monstar-216/Downloads/"+str(input['user_id'])+".txt"

#打包成文件
def m_pack(data=None):
    if data is None:
        return
    packed = packb(input)
    with open(FILE_PATH, "wb+") as f:
        f.write(packed)
        #print f.read()
    
    #print unpackb(packed, encoding="utf-8")
    
#从文件中解包
def m_unpack(filename):
    
    with open(FILE_PATH, "rb") as f:
        unpacked = unpackb(f.read())
        print unpacked
'''
if __name__ == "__main__":
    m_pack(data)
    m_unpack(None)
'''
        
import urllib2

if __name__ == "__main__":
    message = packb(input)
    uri = "http://192.168.10.237/special_stage/place/1/time/3"
    req = urllib2.Request(uri, data=message)
    req.add_header('Content-Type', 'text/plain')
    #req.add_header('Content-Length', 100)
    req.add_header('Content-Disposition', 'form-data; name="data"; filename="100059076.txt"')
    res_data = urllib2.urlopen(req)
    res = res_data.read()
    print res
    